/*
 * Lenovo Group
 * Copyright (c) 2015-2016 All Rights Reserved.
 * Project Name: lmrp-android app
 * Create Time: 16-2-16 下午6:42
 */

package com.lenovo.mso2o.ui.adapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;

import java.util.List;

/**
 * Created by lit on 2015/11/12.
 */
public class AdViewPagerAdapter extends PagerAdapter {

    List<View> viewLists;
    Context context;
    public AdViewPagerAdapter(Context context, List<View> theImges){
        this.context=context;
        viewLists=theImges;
    }
    public void setList(List<View> theImges){
        viewLists=theImges;
        this.notifyDataSetChanged();
    }
    @Override
    public int getCount() {
        return viewLists.size();
    }

    @Override
    public boolean isViewFromObject(View arg0, Object arg1) {
        return arg0 == arg1;
    }

    @Override
    public void destroyItem(View container, int position, Object object) {
        if(position < mChildCount)
        ((ViewPager)container).removeView(viewLists.get(position));

    }

    @Override
    public Object instantiateItem(View container, int position) {
        ((ViewPager)container).addView(viewLists.get(position));
        return viewLists.get(position);
    }

    private int mChildCount = 0;

    @Override

    public void notifyDataSetChanged() {

        mChildCount = getCount();

        super.notifyDataSetChanged();

    }



    @Override

    public int getItemPosition(Object object)   {

        if (mChildCount > 0) {

            mChildCount --;

            return POSITION_NONE;

        }

        return super.getItemPosition(object);

    }


}
